#ifndef CFRACTION_H_
#define CFRACTION_H_

#include <ostream>
#include <math.h>
#include "../base/cobject.h"

/**
 * CFraction - class representing fraction
 * @author Michal Rost
 * @date 15.04.2007
 */
class CFraction : public CObject {
public:
  CFraction();
  CFraction(int num);
  CFraction(long num);
  CFraction(long numerator, long denominator);
  CFraction& toCommonBase(long &numerator, long &denominator);
  CFraction& operator += (const CFraction &f);
  CFraction& operator -= (const CFraction &f);
  CFraction& operator *= (const CFraction &f);
  CFraction& operator /= (const CFraction &f);
  CFraction operator + (const CFraction &f) const;
  CFraction operator - (const CFraction &f) const;
  CFraction operator * (const CFraction &f) const;
  CFraction operator / (const CFraction &f) const;
  CFraction operator - () const;
  bool operator == (const CFraction &f) const;
  bool operator != (const CFraction &f) const;
  bool operator > (const CFraction &f) const;
  bool operator < (const CFraction &f) const;
  bool operator >= (const CFraction &f) const;
  bool operator <= (const CFraction &f) const;
  bool operator ! () const;
  void set(long numerator, long denominator);
  long getNumerator() const;
  long getDenominator() const;
  friend std::ostream& operator << (std::ostream &out, CFraction &f) {
    return out << f.getNumerator() << "/" << f.getDenominator();
  }
  static std::string getClassName() {
    return "CFraction";
  }
protected:
  long numerator, denominator;
  void reduce();
};

#endif
